//跟进计划列表
var $customerPayFromTable = $('#customerPayFrom');
var $balanceTable = $('#balanceTable')
//充值记录
var $rechargeRecordTable = $('#rechargeRecordTable');
//消费记录
var $expensesRecordTable = $('#expensesRecordTable')
var abs = new verjs_select();
//防止表头与表格不对齐
$(window).resize(function () {
    $customerPayFromTable.bootstrapTable('resetView');
});

$(function () {

    //初始化列表
    customerPayFromList();
    //加载客户列表
    getCustomerSelect();

    balanceTableInit();

    $('.modal').on('show.bs.modal', function () {
        $(this).find('.modal-dialog').draggable();
    });
})

function customerPayFromList() {
//先销毁表格
    $customerPayFromTable.bootstrapTable('destroy');
    $customerPayFromTable.bootstrapTable({
        classes: 'table table-hover table-bordered table-striped',
        url: '/customerPay/selectCustomerPayList',//请求地址
        method: 'get',//请求方式
        contentType: "application/x-www-form-urlencoded",//请求内容类型
        dataType: "json",//数据类型
        striped: true,//是否显示行间隔色
        sortable: true,//是否启用排序
        sortOrder: "desc",//排序方式
        sortName: 'createTm',//排序字段
        cache: false,//是否使用缓存
        showColumns: false,//显示隐藏列
        showRefresh: false,//显示刷新按钮
        showToggle: false,//切换显示样式
        showFooter: false,//显示Table脚部
        pagination: true,//是否显示分页
        showPaginationSwitch: false,//是否显示分页按钮
        clickToSelect: false,//是否启用点击选中行
        singleSelect: false,
        minimumCountColumns: 2,//最少要显示的列数
        undefinedText: '',//cell没有值时显示
        sidePagination: "server",//分页方式：client客户端分页，server服务端分页
        pageSize: globalPageSize,//每页的记录行数
        pageNumber: 1,//初始化加载第1页，默认第1页
        pageList: globalPageList,//可供选择的每页的行数
        height:400,
        queryParams: queryParams,//查询参数
        columns: [
            {title: '主键', field: 'customerPayId', visible: false},
            {title: '序号', field: 'index', align: 'center', valign: 'left', formatter: indexFormat},
            {title: '客户名称',field: 'customerName', align: 'left', valign: 'middle'},
            {title: '充值金额',field: 'payMoney', align: 'left', valign: 'middle'},
            {title: '充值码',field: 'payNumber', align: 'left', valign: 'middle'},
            {title: '充值类型', field: 'payType', align: 'left', valign: 'middle',formatter: payTypeFormat},
            {title: '充值状态', field: 'payStatus', align: 'left', valign: 'middle',formatter: payStatusFormat},
            {title: '申请人', field: 'createPeopleName', align: 'left', valign: 'middle'},
            {title: '申请时间', field: 'createTm', sortable: true,align: 'left', valign: 'middle'},
            {title: '操作',field: 'operate',align: 'left',formatter: genderOpt}
        ],
        responseHandler: function (result) {
            if (result.code == "000000") {
                var obj = {
                    "rows": result.data,
                    "total": result.totalRecords//总条数
                };
            } else {
                var obj = {
                    "total": 0,
                    "rows": [],
                }
            }
            return obj;
        },
        onLoadSuccess: function () {
            //加载成功时执行
            $("[data-toggle='tooltip']").tooltip();//加这个是为了让操作列的提示图标显示在上方

            // table列可拖动宽度
            $('.JCLRgrips').remove();
            $('#taxDiscFrom').css({
                minWidth: $('#taxDiscFrom').width()
            }).colResizable({
                resizeMode: 'overflow',
                liveDrag: true,
                gripInnerHtml: "<div class='grip'></div>",
                draggingClass: "dragging",
                disabledColumns: [0,11,],      // 禁止拖动的列
                postbackSafe: true,                                         // 刷新后保持拖动的宽度
                partialRefresh: true,                                       // 刷新表格之后继续保持可拖动功能
                flush: true,
                minWidth: 80,
                /*onResize: function () {
                }*/
            });
        },
        onLoadError: function (status) {
            if (status == 403) {
                alert("权限不足！禁止访问！");
            } else {
                //加载失败时执行
                alert("加载失败！");
            }
        },
        formatLoadingMessage: function () {
            return "请稍等，加载中...";
        },
        formatNoMatches: function () {
            return '无符合条件的记录';
        },
    });
}


function searchOrderList() {
    $('.all').addClass('active-second');
    $('.today').removeClass('active-second');
    $('.week').removeClass('active-second');
    $('.month').removeClass('active-second');
    $('.year').removeClass('active-second');
    $("#dateType").val("all");
    $customerPayFromTable.bootstrapTable('refreshOptions', {pageNumber: 1, queryParams: queryParams});
}

function queryParams(params){
    params.pageSize = params.limit;
    params.pageIndex = (params.offset / params.limit) + 1;
    params.sortName = params.sort; //排序列名
    params.sortOrder = params.order;//排序方式
    //搜索条件
    params.customerName = $.trim($('#customerName').val());//客户名称
    params.dataType = 1;//充值类型查询普通充值的
    params.dateType = $.trim($('#dateType').val());
    return params;
}

function indexFormat(value, row, index) {
    return index + 1;
}

/**
 * 获得客户名称下拉
 */
function getCustomerSelect(){
    $.ajax({
        type: 'POST',
        dataType: "json",
        url: '/customerController/getCustomerList',
        cache : false,
        data:{
        },
        async : true,
        success: (function (data) {
            if (data.code == "000000") {
                var html = '<option value="">请选择</option>';
                $.each(data.data, function(n, value) {
                    html += "<option value=" + value.customerId + ">" +  value.customerName + "</option>";
                });

                $('#customerInput').html(html).selectpicker('refresh');
            } else {
                alert("请求失败");
            }
        }),
        error: (function (res) {
            alert("请求失败");
        })
    });
}


/**
 * 自定义操作列内容
 */
function genderOpt(value, row, index) {
    let html = '';
    html += '<button class="btn btn-default"' +
        'onclick="updatePay(\''+row.customerId+'\',\''+row.customerPayId+'\',\''+row.payMoney+'\',\''+row.customerName+'\',\''+row.payStatus+'\')">修改</button>';
    html += '<button class="btn btn-default"' +
        'onclick="delPay(\''+row.customerPayId+'\',\''+row.payStatus+'\')">删除</button>';
    /*html += '<button class="btn btn-default" ' +
        'onclick="delTaxDisc(\''+row.companyId+'\')">删除</button>';*/

    html += '</ul></div>'
    return html;
}


/**
 * 获得客户名称下拉
 */
function getCustomerSelect2(customerId){
    $.ajax({
        type: 'POST',
        dataType: "json",
        url: '/customerController/getCustomerList',
        cache : false,
        data:{
        },
        async : true,
        success: (function (data) {
            if (data.code == "000000") {
                var html = '<option value="">请选择</option>';
                $.each(data.data, function(n, value) {
                    if (value.customerId == customerId){
                        html += "<option value=" + value.customerId + " selected >" +  value.customerName + "</option>";
                    }else {
                        html += "<option value=" + value.customerId + ">" +  value.customerName + "</option>";
                    }

                });

                $('#customerInput2').html(html).selectpicker('refresh');
            } else {
                alert("请求失败");
            }
        }),
        error: (function (res) {
            alert("请求失败");
        })
    });
}

function delPay(customerPayId,payStatus) {
    if (payStatus == 1){
        $.alert("该条充值信息财务已经确认收款，不能删除");
        return;
    }
    $.alert({
        title: '提示',
        content: '您确认要修改客户充值信息吗？',
        buttons: {
            confirm: {
                text: '确认',
                btnClass: 'btn-primary',
                action: function () {
                    $.ajax({
                        url: '/customerPay/deleteCustomerPay?customerPayId='+customerPayId,
                        type: 'POST',
                        dataType: "json",
                        contentType: "application/json;charset=utf-8",
                        success: (function (data) {
                            if (data.code == "000000") {
                                $.alert({
                                    title: '提示',
                                    content: '操作成功！',
                                    buttons: {
                                        confirm: {
                                            text: '确认',
                                            btnClass: 'btn-primary',
                                            action: function () {
                                                // window.location.reload();
                                                $('#updatePay').modal('hide')
                                                customerPayFromList()
                                            }
                                        }
                                    }
                                });
                            } else {
                                $.alert(data.message);
                            }
                        }),
                        error: (function (res) {
                            $.alert('操作失败，请稍后再试!');
                        })
                    });
                }
            },
            cancel: {
                text: '取消',
                action: function () {
                }
            }
        }
    });

}

//回显
function updatePay(customerId,customerPayId,payMoney,customerName,payStatus) {
    if (payStatus == 1){
        $.alert("该条充值信息财务已经确认收款，不能修改");
        return;
    }
    $('#updatePay').modal('show')
    $("#customerPayIdHide").val(customerPayId);
    $("#payMoney2").val(payMoney);
    getCustomerSelect2(customerId);
}

//修改
function subUpdateCustomerPay() {
    $.alert({
        title: '提示',
        content: '您确认要修改客户充值信息吗？',
        buttons: {
            confirm: {
                text: '确认',
                btnClass: 'btn-primary',
                action: function () {
                    var customerPayId = $("#customerPayIdHide").val();
                    var customerId = $("#customerInput2").val();
                    var payMoney = $("#payMoney2").val();
                    var jsonData = {
                        "chsCustomerPayId":customerPayId,
                        "customerId":customerId,
                        "payMoney":payMoney,
                        "payType":1
                    }
                    $.ajax({
                        url: '/customerPay/updateCustomerPay',
                        type: 'POST',
                        dataType: "json",
                        contentType: "application/json;charset=utf-8",
                        data: JSON.stringify(jsonData),
                        success: (function (data) {
                            if (data.code == "000000") {
                                $.alert({
                                    title: '提示',
                                    content: '操作成功！',
                                    buttons: {
                                        confirm: {
                                            text: '确认',
                                            btnClass: 'btn-primary',
                                            action: function () {
                                                // window.location.reload();
                                                $('#updatePay').modal('hide')
                                                customerPayFromList()
                                            }
                                        }
                                    }
                                });
                            } else {
                                $.alert(data.message);
                            }
                        }),
                        error: (function (res) {
                            $.alert('操作失败，请稍后再试!');
                        })
                    });
                }
            }
        }
    });

}

//添加充值
function addPay() {
    var customerId = $("#customerInput").val();
    var payMoney = $("#payMoney").val();
    if(payMoney <= 0) {
        $.alert("充值金额必须大于0");
        return;
    }
    var jsonData = {
        "customerId":customerId,
        "payMoney":payMoney,
        "payType":1
    }
    $.ajax({
        url: '/customerPay/saveCustomerPay',
        type: 'POST',
        dataType: "json",
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify(jsonData),
        success: (function (data) {
            if (data.code == "000000") {
                $.alert({
                    title: '提示',
                    content: '操作成功！',
                    buttons: {
                        confirm: {
                            text: '确认',
                            btnClass: 'btn-primary',
                            action: function () {

                                // $('#addPay').modal('hide')
                                customerPayFromList();
                                clearAllData(1)
                            }
                        }
                    }
                });
            } else {
                $.alert(data.message);
            }
        }),
        error: (function (res) {
            $.alert('操作失败，请稍后再试!');
        })
    });
}

function clearAllData(btn) {
    console.log(btn)
    if(btn == 1){
        // $('#addPay').modal('hide')
        // $('#addPay').css('display','none')
        $('#customerInput').val('').selectpicker('refresh');
        $('#payMoney').val('')
    }else{
        $('#updatePay').modal('hide')
        // $('#updatePay').css('display','none')
    }

}


function getCompanyTaxNumber(companyId) {
    $.ajax({
        url: "/sysCompany/selectCompanyTaxNumber?companyId="+companyId,
        dataType: 'json',
        contentType: "application/x-www-form-urlencoded",
        success: function (data) {
            var data = data.data;
            $("#taxNumber").val(data);
        },
        error: function (err) {
            console.log(err);
        }
    })
}

function payTypeFormat(value, row, index) {
    var html = "";
    if (value == 1){
        html = "普通充值";
    }
    if (value == 2){
        html = "转入额";
    }
    return html;
}

function payStatusFormat(value, row, index) {
    var html = "";
    if (value == 0){
        html = "充值中";
    }
    if (value == 1){
        html = "已到账";
    }
    return html;
}

/**
 * 全部/周/月/年切换
 * @param time
 */
function selectTime(time) {
    if (time == 'all') {//全部
        $('.all').addClass('active-second');
        $('.year').removeClass('active-second');
        $('.week').removeClass('active-second');
        $('.month').removeClass('active-second');
        $('.today').removeClass('active-second');
        $("#dateType").val("all");
    }
    if (time == 'year') {//本年
        $('.year').addClass('active-second');
        $('.all').removeClass('active-second');
        $('.week').removeClass('active-second');
        $('.month').removeClass('active-second');
        $('.today').removeClass('active-second');
        $("#dateType").val("3");
    }
    if (time == 'month') {//本月
        $('.month').addClass('active-second');
        $('.all').removeClass('active-second');
        $('.year').removeClass('active-second');
        $('.week').removeClass('active-second');
        $('.today').removeClass('active-second');
        $("#dateType").val("2");
    }
    if (time == 'week') {//本周
        $('.week').addClass('active-second');
        $('.all').removeClass('active-second');
        $('.year').removeClass('active-second');
        $('.month').removeClass('active-second');
        $('.today').removeClass('active-second');
        $("#dateType").val("1");
    }
    if (time == 'today') {//今天
        $('.today').addClass('active-second');
        $('.week').removeClass('active-second');
        $('.all').removeClass('active-second');
        $('.year').removeClass('active-second');
        $('.month').removeClass('active-second');
        $("#dateType").val("4");
    }
    $customerPayFromTable.bootstrapTable('refreshOptions', {pageNumber: 1, queryParams: queryParams});
}

//
// function changeTab(type){
//     if(type == 'customerRechargeTab'){
//         $('#customerRecharge').show();
//         $('#balance').hide()
//     }else if(type == 'balanceTab'){
//         $('#customerRecharge').hide();
//         $('#balance').show()
//     }
// }

function balanceTableInit(){
    $balanceTable.bootstrapTable('destroy');
    $balanceTable.bootstrapTable({
        classes: 'table table-hover table-bordered table-striped',
        url: '/customerController/meCustomerList',//请求地址
        method: 'post',//请求方式
        contentType: "application/x-www-form-urlencoded",//请求内容类型
        dataType: "json",//数据类型
        striped: true,//是否显示行间隔色
        sortable: true,//是否启用排序
        sortOrder: "desc",//排序方式
        sortName: 'createTm',//排序字段
        cache: false,//是否使用缓存
        showColumns: false,//显示隐藏列
        showRefresh: false,//显示刷新按钮
        showToggle: false,//切换显示样式
        showFooter: false,//显示Table脚部
        pagination: true,//是否显示分页
        showPaginationSwitch: false,//是否显示分页按钮
        clickToSelect: false,//是否启用点击选中行
        singleSelect: false,
        minimumCountColumns: 2,//最少要显示的列数
        undefinedText: '-',//cell没有值时显示
        sidePagination: "server",//分页方式：client客户端分页，server服务端分页
        pageSize: globalPageSize,//每页的记录行数
        pageNumber: 1,//初始化加载第1页，默认第1页
        pageList: globalPageList,//可供选择的每页的行数
        height:420,
        queryParams: balanceQueryParams,//查询参数
        columns: [

            {title: '主键', field: 'customerId', visible: false},
            {title: '序号', field: 'index', align: 'center', valign: 'left', formatter: indexFormat},
            {title: '客户名称',field: 'customerName', align: 'left', valign: 'middle',sortable: true},
            {title: '余额',field: 'customerWallet', align: 'left', valign: 'middle',sortable: true},
            {title: '操作',field: 'operate',align: 'right',formatter: balanceGenderOpt}
        ],
        responseHandler: function (result) {
            if (result.code == "000000") {
                var obj = {
                    "rows": result.data,
                    "total": result.totalRecords//总条数
                };
            } else {
                var obj = {
                    "total": 0,
                    "rows": [],
                }
            }
            return obj;
        },
        onLoadSuccess: function () {
            //加载成功时执行
            $("[data-toggle='tooltip']").tooltip();//加这个是为了让操作列的提示图标显示在上方

            // table列可拖动宽度
            // $('.JCLRgrips').remove();
            // $('#taxDiscFrom').css({
            //     minWidth: $('#taxDiscFrom').width()
            // }).colResizable({
            //     resizeMode: 'overflow',
            //     liveDrag: true,
            //     gripInnerHtml: "<div class='grip'></div>",
            //     draggingClass: "dragging",
            //     disabledColumns: [0,11,],      // 禁止拖动的列
            //     postbackSafe: true,                                         // 刷新后保持拖动的宽度
            //     partialRefresh: true,                                       // 刷新表格之后继续保持可拖动功能
            //     flush: true,
            //     minWidth: 80,
            //     /*onResize: function () {
            //     }*/
            // });
        },
        onLoadError: function (status) {
            if (status == 403) {
                alert("权限不足！禁止访问！");
            } else {
                //加载失败时执行
                alert("加载失败！");
            }
        },
        formatLoadingMessage: function () {
            return "请稍等，加载中...";
        },
        formatNoMatches: function () {
            return '无符合条件的记录';
        },
    });
}

function balanceQueryParams(params){
    params.pageSize = params.limit;
    params.pageIndex = (params.offset / params.limit) + 1;
    params.sortName = params.sort; //排序列名
    params.sortOrder = params.order;//排序方式
    params.customerName = $('#balanceCustomerName').val();
    return params;
}

function balanceGenderOpt(value,row,index){
    let html = '';
    html += '<button class="btn btn-default"  data-toggle="modal" data-target="#rechargeRecord" onclick="rechargeRecordTableInit(\''+row.customerId +'\')">充值记录</button>';
    html += '<button class="btn btn-default" data-toggle="modal" data-target="#expensesRecord" onclick="expensesRecordTableInit(\''+row.customerId +'\')">消费记录</button>';
    html += '<button class="btn btn-default" data-toggle="modal" data-target="#requestRefund" onclick="requestRefund(\''+row.customerName +'\',\''+row.customerWallet +'\',\''+row.customerId +'\',)">申请退款</button>';
    // html += '<button class="btn btn-default"' +
    //     'onclick="delPay(\''+row.customerPayId+'\',\''+row.payStatus+'\')">删除</button>';
    /*html += '<button class="btn btn-default" ' +
        'onclick="delTaxDisc(\''+row.companyId+'\')">删除</button>';*/

    html += '</ul></div>'
    return html;
}

function rechargeRecordTableInit(id){
    //先销毁表格
    $rechargeRecordTable.bootstrapTable('destroy');
    $rechargeRecordTable.bootstrapTable({
        classes: 'table table-hover table-bordered table-striped',
        url: '/customerPay/selectCustomerPayList',//请求地址
        method: 'get',//请求方式
        contentType: "application/x-www-form-urlencoded",//请求内容类型
        dataType: "json",//数据类型
        striped: true,//是否显示行间隔色
        sortable: true,//是否启用排序
        sortOrder: "desc",//排序方式
        sortName: 'createTm',//排序字段
        cache: false,//是否使用缓存
        showColumns: false,//显示隐藏列
        showRefresh: false,//显示刷新按钮
        showToggle: false,//切换显示样式
        showFooter: false,//显示Table脚部
        pagination: true,//是否显示分页
        showPaginationSwitch: false,//是否显示分页按钮
        clickToSelect: false,//是否启用点击选中行
        singleSelect: false,
        minimumCountColumns: 2,//最少要显示的列数
        undefinedText: '',//cell没有值时显示
        sidePagination: "server",//分页方式：client客户端分页，server服务端分页
        pageSize: globalPageSize,//每页的记录行数
        pageNumber: 1,//初始化加载第1页，默认第1页
        pageList: globalPageList,//可供选择的每页的行数
        queryParams: function(params){
            params.pageSize = params.limit;
            params.pageIndex = (params.offset / params.limit) + 1;
            params.sortName = params.sort; //排序列名
            params.sortOrder = params.order;//排序方式
            params.customerId = id;
            return params;
        },//查询参数
        columns: [
            {title: '主键', field: 'customerPayId', visible: false},
            {title: '充值码',field: 'payNumber', align: 'left', valign: 'middle'},
            {title: '充值时间',field: 'createTm', align: 'left', valign: 'middle'},
            {title: '充值金额',field: 'payMoney', align: 'left', valign: 'middle'},
            {title: '录入人', field: 'financeName', align: 'left', valign: 'middle'},
            {title: '操作',field: 'operate',align: 'left'}
        ],
        responseHandler: function (result) {
            if (result.code == "000000") {
                console.log(result)
                var obj = {
                    "rows": result.data,
                    "total": result.totalRecords//总条数
                };
            } else {
                var obj = {
                    "total": 0,
                    "rows": [],
                }
            }
            return obj;
        },
        onLoadSuccess: function () {
            //加载成功时执行
            $("[data-toggle='tooltip']").tooltip();//加这个是为了让操作列的提示图标显示在上方

            // // table列可拖动宽度
            // $('.JCLRgrips').remove();
            // $('#taxDiscFrom').css({
            //     minWidth: $('#taxDiscFrom').width()
            // }).colResizable({
            //     resizeMode: 'overflow',
            //     liveDrag: true,
            //     gripInnerHtml: "<div class='grip'></div>",
            //     draggingClass: "dragging",
            //     disabledColumns: [0,11,],      // 禁止拖动的列
            //     postbackSafe: true,                                         // 刷新后保持拖动的宽度
            //     partialRefresh: true,                                       // 刷新表格之后继续保持可拖动功能
            //     flush: true,
            //     minWidth: 80,
            //     /*onResize: function () {
            //     }*/
            // });
        },
        onLoadError: function (status) {
            if (status == 403) {
                alert("权限不足！禁止访问！");
            } else {
                //加载失败时执行
                alert("加载失败！");
            }
        },
        formatLoadingMessage: function () {
            return "请稍等，加载中...";
        },
        formatNoMatches: function () {
            return '无符合条件的记录';
        },
    });
}

function expensesRecordTableInit(id) {
    //先销毁表格
    $expensesRecordTable.bootstrapTable('destroy');
    $expensesRecordTable.bootstrapTable({
        classes: 'table table-hover table-bordered table-striped',
        url: '/finishOrderProduct/selectBalanceOrderFinishProduct',//请求地址
        method: 'post',//请求方式
        contentType: "application/x-www-form-urlencoded",//请求内容类型
        dataType: "json",//数据类型
        striped: true,//是否显示行间隔色
        sortable: true,//是否启用排序
        sortOrder: "desc",//排序方式
        sortName: 'createTm',//排序字段
        cache: false,//是否使用缓存
        showColumns: false,//显示隐藏列
        showRefresh: false,//显示刷新按钮
        showToggle: false,//切换显示样式
        showFooter: false,//显示Table脚部
        pagination: true,//是否显示分页
        showPaginationSwitch: false,//是否显示分页按钮
        clickToSelect: false,//是否启用点击选中行
        singleSelect: false,
        minimumCountColumns: 2,//最少要显示的列数
        undefinedText: '',//cell没有值时显示
        sidePagination: "server",//分页方式：client客户端分页，server服务端分页
        pageSize: globalPageSize,//每页的记录行数
        pageNumber: 1,//初始化加载第1页，默认第1页
        pageList: globalPageList,//可供选择的每页的行数
        queryParams: function(params){
            params.pageSize = params.limit;
            params.pageIndex = (params.offset / params.limit) + 1;
            params.sortName = params.sort; //排序列名
            params.sortOrder = params.order;//排序方式
            params.customerId = id;

            return params;
        },//查询参数
        columns: [
            {title: '主键', field: 'customerPayId', visible: false},
            {title: '产品编号', field: 'finishOrderProductNum', align: 'center', valign: 'left'},
            {title: '购买产品',field: 'productName', align: 'left', valign: 'middle'},
            {title: '购买时间',field: 'createTm', align: 'left', valign: 'middle'},
            {title: '产品状态', field: 'productStatus', align: 'left', valign: 'middle'},
            // {title: '操作',field: 'operate',align: 'left'}
        ],
        responseHandler: function (result) {
            if (result.code == "000000") {
                console.log(result)
                var obj = {
                    "rows": result.data,
                    "total": result.totalRecords//总条数
                };
            } else {
                var obj = {
                    "total": 0,
                    "rows": [],
                }
            }
            return obj;
        },
        onLoadSuccess: function () {
            //加载成功时执行
            $("[data-toggle='tooltip']").tooltip();//加这个是为了让操作列的提示图标显示在上方

            // // table列可拖动宽度
            // $('.JCLRgrips').remove();
            // $('#taxDiscFrom').css({
            //     minWidth: $('#taxDiscFrom').width()
            // }).colResizable({
            //     resizeMode: 'overflow',
            //     liveDrag: true,
            //     gripInnerHtml: "<div class='grip'></div>",
            //     draggingClass: "dragging",
            //     disabledColumns: [0,11,],      // 禁止拖动的列
            //     postbackSafe: true,                                         // 刷新后保持拖动的宽度
            //     partialRefresh: true,                                       // 刷新表格之后继续保持可拖动功能
            //     flush: true,
            //     minWidth: 80,
            //     /*onResize: function () {
            //     }*/
            // });
        },
        onLoadError: function (status) {
            if (status == 403) {
                alert("权限不足！禁止访问！");
            } else {
                //加载失败时执行
                alert("加载失败！");
            }
        },
        formatLoadingMessage: function () {
            return "请稍等，加载中...";
        },
        formatNoMatches: function () {
            return '无符合条件的记录';
        },
    });
}

function requestRefund(name,money,id){
    $('#currentCustomer').text(name);
    $('#currentRefundMoney').text(money);
    $('#customId').val(id)
}

function submit() {
    var refundSwitch;
    $.ajax({
        url: "/systemParameterSetting/selectSystemParameterSetting",
        type: 'GET',
        datatype: 'json',
        async: false,
        success: function (data) {
            if (data) {
                if (data.code == '000000') {
                    refundSwitch = data.data.refundSwitch;
                }
            }
        }
    });

    if("N" == refundSwitch) {
        $.alert('退款控制已关闭!');
        return;
    }

    if(new Date().getDate() <= 10){
        $.alert('每月1到10号不能申请退款!');
        return;
    }

    if($('#refundMoney').val() == '' || Number($('#refundMoney').val()) < 1){
        $.alert('退款金额不能为空并且要大于0');
        return;
    }
    if(Number($('#refundMoney').val()) > Number($('#currentRefundMoney').text())){
        $.alert('退款金额不能大于余额');
        return;
    }
    $.ajax({
        url: '/order/balanceRefund',
        type: 'POST',
        dataType: "json",
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify({
            "customerId":$('#customId').val(),  //客户id
            "sqbz":$('#refundMake').val(),  //申请退款备注
            "applyBackMoney":$('#refundMoney').val(),  //申请退款金额
        }),
        success: (function (data) {
            if (data.code == "000000") {
                $.alert({
                    title: '提示',
                    content: data.message,
                    buttons: {
                        confirm: {
                            text: '确认',
                            btnClass: 'btn-primary',
                            action: function () {
                                $('#requestRefund').modal('hide');
                                balanceTableInit()
                                $('#refundMoney').val('');
                                $('#refundMake').val('');
                            }
                        }
                    }
                });
            }else{
                $.alert(data.message);
            }
        }),
        error: (function (res) {
            $.alert('操作失败，请稍后再试!');
        })
    });
}